
// ##############################
// ####  note:  bokeweilai protocol jiwei main fun
// ####  create:  TANWENHUI (twh:谭文辉)
// ####  date:   2024/6/18
// ##############################

#ifndef __BKWL_PROTOCOL_JIWEI_H__
#define __BKWL_PROTOCOL_JIWEI_H__
#include "bkwl_common.h"

#define BKWL_JIWEI_CMD_LEN 10
#define BKWL_JIWEI_CMD_WIFI_ACK 0x02
#define BKWL_JIWEI_CMD_ACK_OK 0x00
#define BKWL_JIWEI_CMD_ACK_PAIR_FAIL 0x02

typedef enum
{
    BKWL_CMD_ENABLED_BT = 10,
} bkwl_event_dev_cmd_e;
typedef enum
{
    BKWL_CMD_DOOR_START_WIFI_PAIR = 60,
    BKWL_CMD_DOOR_MESSAGE,
    BKWL_CMD_DOOR_POWER_OFF,
    BKWL_CMD_DOOR_CLEAN_DATA,
    BKWL_CMD_DOOR_GET_DEVICE_INFO,
    BKWL_CMD_DOOR_UPGRADE,
    BKWL_CMD_DOOR_PRODUCT_TEST,
    BKWL_CMD_DOOR_GET_NET_TIME,
    BKWL_CMD_DOOR_ACK_REMOTE_UNLOCK,
    BKWL_CMD_DOOR_UPLOAD_IMAGE,
    BKWL_CMD_DOOR_USER_VERIFY,
    BKWL_CMD_DOOR_START_UPLOAD_IMAGE,
    BKWL_CMD_DOOR_VIDEO_STATUS_NOTIFY,
    BKWL_CMD_DOOR_VIDEO_PARA_SETUP,
    BKWL_CMD_DOOR_STATUS_REPORT,
    BKWL_CMD_DOOR_STOP_WIFI_PAIR,
    BKWL_CMD_DOOR_CACHE_MESSAGE,
    BKWL_CMD_DOOR_DEVICE_FUNC,
    BKWL_CMD_DOOR_LOOK_SETUP,
    BKWL_CMD_DOOR_GET_VERSION,
    BKWL_CMD_DOOR_GET_WEATHER,
    BKWL_CMD_DOOR_GET_REGION,

} bkwl_event_door_cmd_e;

typedef enum
{
    BKWL_DOOR_MSG_EVENT_HAVE_LOCK = 0,  // 已锁上(0x00)
    BKWL_DOOR_MSG_EVENT_UNLOCK,         // 已打开(0x01)
    BKWL_DOOR_MSG_EVENT_ALARM,          // 报警(0x02)
    BKWL_DOOR_MSG_EVENT_REQUEST_UNLOCK, // 远程开锁请求(0x03)
    BKWL_DOOR_MSG_EVENT_NOTICE,         // 提醒(0x04)
} bkwl_door_mSg_event_e;

typedef enum
{
    BKWL_CMD_PROTOCOL_MQTT_INIT = 100,
} bkwl_event_protocol_cmd_e;

typedef struct
{
    uint8_t type;
    uint8_t notify;
} bkwl_door_wifi_pair_t;
typedef struct
{
    uint8_t event;
    uint8_t info;
    uint8_t user_type;
    uint8_t user_num;
} bkwl_door_message_t;
typedef struct
{
    uint8_t mode;
} bkwl_door_power_off_t;
typedef struct
{
    uint8_t utc[4];
    uint8_t zone;
    uint8_t type;
    uint8_t pwd_len;
    uint8_t pwd[32];
} bkwl_door_user_verify_t;

typedef struct
{
    uint8_t baudrate;
    uint16_t image_size;
    uint16_t verify_value;
} bkwl_door_setup_image_upload_t;

typedef struct
{
    uint8_t language;
    uint8_t speaker_volume;
    uint8_t image_rotate;
} bkwl_door_video_para_setup_t;

typedef struct
{
    uint16_t type;
    uint32_t value;
} bkwl_door_status_report_t;
typedef struct
{
    uint32_t utc;
    uint8_t event;
    uint8_t info;
    uint8_t user_type;
    uint16_t user_num;
} bkwl_door_cache_message_t;

typedef struct
{
    uint8_t look;
    uint8_t wakeup_label;
    uint8_t wakeup_time;
} bkwl_door_look_setup_t;

extern uint32_t bkwl_protocol_jiwei_get_cmd_len(uint8_t cmd, uint8_t *data, uint32_t len);
extern uint32_t bkwl_protocol_jiwei_get_cmd_handle(uint8_t *data, uint32_t len);
extern bkwl_err_t bkwl_protocol_jiwei_checksum(uint8_t *data, uint32_t len);
extern bkwl_err_t bkwl_protocol_jiwei_parse(uint8_t *data, uint32_t len);

extern bkwl_err_t bkwl_protocol_jiwei_door_ack(uint8_t cmd, uint8_t status, uint8_t ack_cmd);

extern bkwl_err_t bkwl_protocol_init_door_queue(beken_queue_t queue);

#endif
